/*
 * Project CHEN Rendering Engine : /strc.hpp
 * Created: 2021-01-29, Last modified:  2021-01-29
 * 
 * This file declares datastructures for use.
 * 
 * Copyright (C) 2021 Hineven (hineven@pku.edu.cn)
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#ifndef _H_STRC
#define _H_STRC
#include "heads.hpp"
#include "shape.hpp"
namespace chen {
class Structure {
public:
	std::vector<const Shape*> shapes;
	Structure (const std::vector<const Shape*> & shas): shapes(shas) {}
	virtual bool castRay (const Ray & r, SurfInteract * si) const = 0;
	virtual const Shape * testRay (const Ray & r) const = 0;
	virtual ~Structure () {}
};
class BasicStructure: public Structure {
    public:
    using Structure::Structure;
    bool castRay (const Ray & r, SurfInteract *si) const {
        bool flag = false;
        for(auto it = Structure::shapes.begin(); it != Structure::shapes.end(); it++) {
            if((*it)->interact(r, si)) {
                flag = true;
            }
        }
        return flag;
    }
    const Shape * testRay (const Ray & r) const {
        const Shape * ret = nullptr;
        for(auto it = Structure::shapes.begin(); it != Structure::shapes.end(); it++) {
            if((*it)->mask(r)) {
                ret = *it;
            }
        }
        return ret;
    }
};
}
#endif